// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Settings.cs" company="XamlNinja">
//   2011 Richard Griffin and Ollie Riches
// </copyright>
// <summary>
//   Settings.cs
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WP7Contrib.Services.DownloadManager
{
    using System;
    using System.Collections.Generic;
    using Common;
    using Communications;

    /// <summary>
    /// Defines the setting for the downloader.
    /// </summary>
    public sealed class Settings : BaseModel,  ISettings
    {
        private int blockSize;
        private int retryCount;
        private IEnumerable<NetworkType> networkTypes;

        /// <summary>
        /// Default block size used http 'accept-range' header - not sure what would be the best TCP MSS for a mobile device.
        /// </summary>
        private const int DefaultBlockSize = 32768;

        /// <summary>
        /// Default retry count
        /// </summary>
        private const int DefaultRetryCount = 3;

        /// <summary>
        /// Default network types supported - included all for now :)
        /// </summary>
        private static readonly IList<NetworkType> DefaultNetworkTypes = new[] { NetworkType.Wireless, NetworkType.Ethernet };

        public Settings()
            : this(DefaultBlockSize, DefaultRetryCount, DefaultNetworkTypes)
        {
        }

        public Settings(int blockSize)
            : this(blockSize, DefaultRetryCount, DefaultNetworkTypes)
        {
        }

        public Settings(int blockSize, int retryCount)
            : this(blockSize, retryCount, DefaultNetworkTypes)
        {
        }

        public Settings(IEnumerable<NetworkType> networkTypes)
            : this(DefaultBlockSize, networkTypes)
        {
        }

        public Settings(int blockSize, IEnumerable<NetworkType> networkTypes)
            : this(blockSize, DefaultRetryCount, networkTypes)
        {
        }

        public Settings(int blockSize, int retryCount, IEnumerable<NetworkType> networkTypes)
        {
            this.BlockSize = blockSize;
            this.RetryCount = retryCount;
            this.NetworkTypes = networkTypes;
        }
        
        /// <summary>
        /// Block size used for resumable downloads.
        /// </summary>
        public int BlockSize
        {
            get
            {
                return this.blockSize;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.blockSize, value, () => BlockSize);
            }
        }

        /// <summary>
        /// Retry count for resumable downloads.
        /// </summary>
        public int RetryCount
        {
            get
            {
                return this.retryCount;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.retryCount, value, () => RetryCount);
            }
        }

        /// <summary>
        /// Supported networks types for downloads (both download types).
        /// </summary>
        public IEnumerable<NetworkType> NetworkTypes
        {
            get
            {
                return this.networkTypes;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.networkTypes, value, () => NetworkTypes);
            }
        }
    }
}